package file;

import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;

public class CreateTempFile {
    public static void main(String[] args) throws IOException, InterruptedException {
        final File htmlFile = File.createTempFile("temp", ".html");//创建临时文件
        System.out.println("临时文件所在的本地路径：" + htmlFile.getCanonicalPath());
        FileOutputStream fos = new FileOutputStream(htmlFile);
        try {
            //这里处理业务逻辑
        } finally {
            //关闭临时文件
            fos.flush();
            fos.close();
            Thread.sleep(1000000);
            htmlFile.deleteOnExit();//程序退出时删除临时文件
        }
    }
}
